<?php
session_start();
$pathArr = explode("/", $_SERVER["PHP_SELF"]);
$contextPath = $pathArr[1];
$rootPath = $_SERVER["DOCUMENT_ROOT"];

$userType=$_SESSION["user_type"];

include $rootPath . "/" . $contextPath . "/apps/ManagerIUDS.php";
$managerIUDS = new ManagerIUDS();
$page = $_GET['page'];
if (!isset($page) && $page == "") {
	$page = 1;
}

$mode=$_GET['mode'];
if (isset($mode) && $mode == "search"){
	$recreationRoomNumber = $_GET['recreation_room_number'];
	$recreationRoomData= $managerIUDS->queryData("recreation_room_id","recreation_room"," WHERE recreation_room_number LIKE '%".$recreationRoomNumber."%'","1","");
	$listBookingRecreationRoom = $managerIUDS->listQueryLimit($page, "booking", "booking_id"," WHERE recreation_room_id = '".$recreationRoomData["recreation_room_id"]."'");
}else{
	$listBookingRecreationRoom = $managerIUDS->listQueryLimit($page, "booking", "booking_id","");
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>.: Pet List :.</title>
<?php
require_once("../includes/css_inc.php");
require_once("../includes/js_inc.php");
?>
<script>
			$(document).ready(function(){ 
				$(function() {
					$( "#combobox" ).combobox();
					$( "#toggle" ).click(function() {
						$( "#combobox" ).toggle();
					});
				});
			}); 
			function deleteBookingRecreationRoomData(bookingId,recreationRoomId) {
				if (confirm("Do you really want to delete?")) {
					window.location = "../actions/booking_action.php?mode=delete&booking_id=" + bookingId+"&recreation_room_id="+recreationRoomId;
				}
			}
			function updateBookingRecreationRoomData(bookingId,recreationRoomId) {
					window.location = "booking_detail.php?mode=update&booking_id=" + bookingId+"&recreation_room_id="+recreationRoomId;
			}
		</script>
</head>
<body>
<table style="width: 100%">
	<thead class="ui-widget">
		<tr class="ui-widget-header">
			<td width="2%" align="center">ลำดับ</td>
			<td width="3%" align="center">เลขที่ห้องพัก</td>
			<td width="5%" align="center">สัตว์เลี้ยง</td>
			<td width="5%" align="center">วันเข้าพัก</td>
			<td width="5%" align="center">วันสิ้นสุดการเข้าพัก</td>
			<td width="3%" align="center">น้ำหนัก</td>
			<td width="3%" align="center">อาหาร</td>
			<td width="3%" align="center">ราคา</td>
			<?php
				if($userType=="A"){
			?>
			<td width="3%" align="center">แก้ไข</td>
			<td width="3%" align="center">checkout</td>
			<?php
				}
			?>
		</tr>
	</thead>
	<tbody class="ui-widget-content">
	<?php
	$i = $listBookingRecreationRoom->startLimit;
	$r = 0;
	$i = ((($page*10)+1)-10);
	if($userType=="A"){
			$colspan="9";
			$colspanButton="11";
	}else{
			$colspan="7";
			$colspanButton="9";
	}
	if(sizeof($listBookingRecreationRoom) > 0){
		foreach ($listBookingRecreationRoom as $value) {
			?>
		<tr>
			<td width="2%" align="center"><?=$i?></td>
			<td width="3%" align="center"><?php 
			$recreationRoomData = $managerIUDS->queryData("recreation_room_number", "recreation_room", " WHERE recreation_room_id='".$value["recreation_room_id"]."'", "1", "");
			echo $recreationRoomData["recreation_room_number"];
			?></td>
			<td width="5%" align="center"><?php 
			$petData = $managerIUDS->queryData("pet_name", "pet", " WHERE pet_id='".$value["pet_id"]."'", "1", "");
			echo $petData["pet_name"];
			?></td>
			<td width="5%" align="center"><?=$value["start_date"]?></td>
			<td width="5%" align="center"><?=$value["end_date"]?></td>
			<td width="5%" align="center"><?php
			if($value["weight"] == "L"){
					echo "อาหารสำหรับสัตว์เลี้ยงน้ำหนักน้อยกว่า 25";
			}else{
					echo "อาหารสำหรับสัตว์เลี้ยงน้ำหนักมากกว่า 25";
			}
			?></td>
			<td width="7%" align="center"><?php
			if($value["is_food"] == "Y"){
				echo "นำมาเอง";
			}else{
				echo "อาหารทางร้าน";
			}
			?></td>
			<td width="3%" align="center"><?=$value["price"]?></td>
			<!--<td width="10%" align="center"><?=$value["species_name"]?></td>
           	   					<td width="20%" align="center"><?=$value["species_detail"]?></td>-->
			<?php
				if($userType=="A"){
			?>
			<td width="3%" align="center">
			<button onclick="updateBookingRecreationRoomData('<?=$value["booking_id"]?>','<?=$value["recreation_room_id"];?>');">
				<span class="ui-icon ui-icon-pencil" title="edit"></span>
			</button>
			</td>
			<td width="3%" align="center">
			<button onclick="deleteBookingRecreationRoomData('<?=$value["booking_id"]?>','<?=$value["recreation_room_id"];?>');">
				<span class="ui-icon ui-icon-trash" title="delete"></span>
			</button>
			<?php
				}
			?>
		</tr>
		<?php
		$i++; $r++;}
		}else{
			if($mode!="search"){
			?>
			<tr>
				<td colspan="<?=$colspan?>" align="center"><font size="2" color="red">ไม่มีข้อมูล!!!</font></td>
			</tr>
			<?php
			}else{
			?>
			<tr>
				<td colspan="<?=$colspan?>" align="center"><font size="2" color="red">ไม่พบข้อมูล</font></td>
			</tr>
			<?php
			}
		}
		?>
		<tr>
			<td align="center" colspan="<?=$colspanButton?>"><?=$managerIUDS->buildPageBtn($page, $managerIUDS->getMaxPageByColumnName("recreation_room", "recreation_room_id"))?></td>
		</tr>
		<tr>
		</tr>
	</tbody>
</table>
</body>
</html>
